// 订单管理的接口

recyceStr = '';
window.onload = function () {
    var btns = document.getElementById("btns").getElementsByTagName("button");
    var divs = document.getElementById("divs").getElementsByTagName("div");
    for (var i = 0; i < btns.length; i++) {
        btns[i].index = i; //自定义属性，用于关联下面的大盒子
        btns[i].onclick = function () {

            for (var j = 0; j < btns.length; j++) {
                //把所有的button清空类名
                btns[j].className = "";
            }
            //点击的那个盒子添加指定类名
            this.className = "color";
            for (var i = 0; i < divs.length; i++) {
                //先让底下的div全部隐藏
                divs[i].style.display = "none";
            }
            //然后给当前所点击按钮相关联的盒子添加指定属性
            console.log(this.index)
            if (this.index == 0) {
                recyceStr = '';
            } else if (this.index == 1) {
                recyceStr = '1';
            } else if (this.index == 2) {
                recyceStr = '2';
            }
            manageList();
            $('#orderContent').html(); //  刷新页面
        }
    }
}


// 查询商家已经成交的订单
function manageList() {
    // var beginTimeStr = today();
    // var endADateStr = today();

    var firstDate = new Date();
    firstDate.setDate(1); // 月第一天
    var nowData=getNowFormatDate();// 今天日期

    // 转化月第一天格式
    var mothonFrist = new XDate(firstDate).toString('yyyy-MM-dd');
    var beginTimeStr = document.getElementById("showDate").innerHTML;
    var endADateStr = document.getElementById("endADate").innerHTML;

    if (beginTimeStr == '选择开始日期') {
        beginTimeStr=mothonFrist;
    } else {
        beginTimeStr = beginTimeStr.replace('年', '-');
        beginTimeStr = beginTimeStr.replace('月', '-');
        beginTimeStr = beginTimeStr.replace('日', '');
    }

    if (endADateStr == '选择结束日期') {
        endADateStr=nowData;
    } else {
        endADateStr = endADateStr.replace('年', '-');
        endADateStr = endADateStr.replace('月', '-');
        endADateStr = endADateStr.replace('日', '');
    }



    // document.getElementById("showHi").innerText =beginTimeStr+" 至 "+ endADateStr+"销售简报";

    // beginTimeStr = beginTimeStr.replace(/\-/g,"");
    // endADateStr = endADateStr.replace(/\-/g,"");

    var newTime = timeAll();
    var timestamp = 'pageNum:'+ 1 +'BM'+'timeStamp:' + newTime + 'BM'+'pageSize:'+10+'BM'+'recycleMethod:'+ recyceStr+'BM'+'startTime:'+ beginTimeStr+'BM'+'endTime:'+ endADateStr +'BM';


    var signs = md5(timestamp);
    signs = signs.toUpperCase();
    $.ajax({
        type: "get",
        url: webUrl + "orderManager/getTransationOrder",
        data: {
            "pageNum": 1,
            "timeStamp": newTime,
            "pageSize": 10,
            "sign": signs,
            "recycleMethod": recyceStr,// 需要获取到对应的值
            "startTime": beginTimeStr,
            "endTime": endADateStr
        },
        dataType: "JSON",
        async: false,
        success: function (data) {
            console.log(data);
            if (data.status == 200) {
                if(data.data.length=='0'){
                    dialog('目前没有成交订单')
                }
                $('#orderContent').html(data); //  刷新页面
                var listAll;
                for (var i = 0; i < data.data.length; i++) {
                    var item = data.data[i];
                    var no = {nameNo:'未知',priceNo:'0'};
                    listAll = '<li class="liDiv" onclick="textsss()">' +
                        '<div class="heardDiv">' +
                        '<div>回收方式：' + (item.recycleMethod!=''?item.recycleMethod:no.nameNo) +
                        '</div>' +
                        '</div>' +
                        '<div class="heardDiv">' +
                        '<div>' +(item.name!=''?item.name:no.nameNo) +
                        '</div>' +
                        '<a class="call" href="tel:'+(item.telephone!=''?item.telephone:no.nameNo)+'">' + '<img class="imgStr" src="../imges/iphone.png">' + '</a>'+
                        '</div>' +
                        '<div class="heardDiv">' + item.address +
                        '</div>' +
                        '<p class="fuMenu">'+'估计报告单' + '</p>' +
                        '<div class="divShou">'+'收起'+'</div>' +
                        '<img class="xiala" src="../imges/xia@1x.png"/>' +
                        '<div class="div1">';
                    var productName = '<div class="zcd">'+ '<div>'+ '名称'+'</div>'+ '<div>' + (item.productDetail.productName!=''?item.productDetail.productName:no.nameNo)+ '</div>'+'</div>';
                    listAll = listAll +productName;
                    for (var j = 0; j < item.productDetail.attrList.length; j++) {

                        var attrListItem = item.productDetail.attrList[j];
                        var typeStr = '<div class="zcd" id=' + attrListItem.attrCategoryId + '>' +
                            '<div>' + attrListItem.attrCategoryName +
                            '</div>' +
                            '<div>' + attrListItem.attrName +
                            '</div>' +
                            '</div>';
                        listAll = listAll + typeStr;
                    }
                    for (var k = 0; k < item.productDetail.problemList.length; k++) {
                        var problemListItem = item.productDetail.problemList[k];
                        var productStr = '<div class="zcd" id="zcd10">' +
                            '<div>' + problemListItem.problemCategoryName +
                            '</div>' +
                            '<div>' + problemListItem.problemName +
                            '</div>' +
                            '<div>' + '-' + (problemListItem.problemPrice!=''?problemListItem.problemPrice:no.priceNo) + '元' +
                            '</div>' +
                            '</div>';
                        listAll = listAll + productStr;
                    }

                    listAll = listAll + '</div>' +
                        '<div class="downDiv">' +
                        '<div class="downDiv2">' +
                        '<div>本单成交价格：</div>' +
                        '<div>' + (item.storePrice!=''?item.storePrice:no.priceNo) + '元' +
                        '</div>' +
                        '</div>' +
                        '<div class="downDiv2">' +
                        '<div>本单上游价格：</div>' +
                        '<div>' + (item.tiptopPrice!=''?item.tiptopPrice:no.priceNo) + '元' +
                        '</div>' +
                        '</div>' +
                        '<div class="downDiv2">' +
                        '<div>赚取差价：</div>' +
                        '<div>' + (item.differencePrice !=''?item.differencePrice:no.priceNo) + '元' +
                        '</div>' +
                        '</div>' +
                        '</div>' +
                        '<div class="orderDiv">' +
                        '<div>下单时间：' + item.createDate +
                        '</div>' +
                        '<div>单号：' + item.orderNum +
                        '</div>' +
                        '</div>';
                    $('#orderContent').append(listAll);

                }
            } else if (data.status == 300) {
                document.location.href = '../html/login.html';
            } else{
                dialog(data.msg);
            };
        },
    })

}


// search设置或返回当前url的查询部分；问号后后面的内容部分
// 查询？ 后面的东西；目的是为了添加订单抓太的值；orderStatus
var strArray = location.search; // 页面间他通过url传值
// 上个页面传递过来的值（index.html）。传值
if (strArray.length != 0) {
    orderStatus = strArray.split("?")[1].split("=")[1];
} else {

}


//  获取当前时间；将时间展示在页面上
function today() {
    var today = new Date();
    var h = today.getFullYear();
    var m = today.getMonth() + 1;
    var d = today.getDate();
    m<10 ?  m = '0'+ m : m;
    d<10 ? d = '0' + d : d;

    return h + "-" + m + "-" + d;
}
// document.getElementById("startDate").value = today();
// document.getElementById("endDate").value = today();

